﻿using System;
using System.Data;
using System.Linq;

namespace Cineplex.Contacts.Models
{
    public class ContactDataModel : ContactModelContextBase
    {
        public Contact GetContact(int id)
        {
            Contact contact = DataModel.Contacts.Single(c => c.ID == id);
            return contact;
        }

        public void AddContact(Contact contact)
        {            
            DataModel.Contacts.AddObject(contact);
            DataModel.SaveChanges();
        }

        public void EditContact(Contact contact)
        {
            DataModel.Contacts.Attach(contact);
            DataModel.ObjectStateManager.ChangeObjectState(contact, EntityState.Modified);
            DataModel.SaveChanges();
        }

        public void Delete(int id)
        {
            Contact contact = this.GetContact(id);
            DataModel.Contacts.DeleteObject(contact);
            DataModel.SaveChanges();
        }
        
    }
}